<?php
function main() {
	$pid = $_POST['id'];
	$mode = $_POST['m'];
	
	if ($mode == null || $pid == null) return 'error';
	
	$post_id = (int) $pid;
	
	if ($mode == 'ru') // `rate up
	{
		$rate_up = get_post_meta($post_id, 'rate-up', true);
		if ($rate_up == '') {
			add_post_meta($post_id, 'rate-up', 1, true);
		} else {
			$rate_up = (int) $rate_up;
			$rate_up++;
			update_post_meta($post_id, 'rate-up', $rate_up);
		}		 
	}
	else if ($mode == 'rd') // `rate down 
	{
		$rate_down = get_post_meta($post_id, 'rate-down', true);
		if ($rate_down == '') {
			add_post_meta($post_id, 'rate-down',10, true);
		} else {
			$rate_down = (int) $rate_down;
			$rate_down++;
			update_post_meta($post_id, 'rate-down', $rate_down);
		}
	}	
	else if ($mode == 'pr') // `previews 
	{
		$previews = get_post_meta($post_id, 'previews', true);
		if ($previews == '') {
			add_post_meta($post_id, 'previews', 1, true);
		} else {
			$previews = (int) $previews;
			$previews++;
			update_post_meta($post_id, 'previews', $previews);
		}
	}	
	else if ($mode == 'dw') // `downloads 
	{
		$downloads = get_post_meta($post_id, 'downloads', true);
		if ($downloads == '') {
			add_post_meta($post_id, 'downloads', 1, true);
		} else {
			$downloads = (int) $downloads;
			$downloads++;
			update_post_meta($post_id, 'downloads', $downloads);
		}
	}	
	else if ($mode == 'in') // `installs 
	{
		$installs = get_post_meta($post_id, 'installs', true);
		if ($installs == '') {
			add_post_meta($post_id, 'installs', 1, true);
		} else {
			$installs = (int) $installs;
			$installs++;
			update_post_meta($post_id, 'installs', $installs);
		}
	}	
	else if ($mode == 'vi') // `views 
	{
		$views = get_post_meta($post_id, 'views', true);
		var_dump($views);
		if ($views == '') {
			var_dump($post_id);
			add_post_meta($post_id, 'views', 1, true);
		} else {
			var_dump('abc');
			$views = (int) $views;
			$views++;
			update_post_meta($post_id, 'views', $views);
		}
	}	
	
	return 'ok';
}

echo main();

?>
